//
//  CommonNewsCell.m
//  HonlivApp
//
//  Created by admin on 2017/6/25.
//  Copyright © 2017年 honliv. All rights reserved.
//

#import "CommonNewsCell.h"

#import "CommonNews.h"
#import "CommonNewsFrame.h"
#import "RemindModel.h"
#import "BSNewsModel.h"
#import "RecommendModel.h"

@interface CommonNewsCell ()

@property (nonatomic,weak) UILabel  *titleLab;
@property (nonatomic,weak) UILabel *timeLab;
@property (nonatomic,weak) UIView *line;

@end

@implementation CommonNewsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        for (UIView *view in self.contentView.subviews) {
            [view removeFromSuperview];
        }
        UILabel *titleLab = [[UILabel alloc] init];
        titleLab.numberOfLines = 0;
        titleLab.textColor = [UIColor darkTextColor];
        titleLab.font = kFont(16);
        [self.contentView addSubview:titleLab];
        self.titleLab = titleLab;
        
        UILabel *timeLab = [[UILabel alloc] init];
        timeLab.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:timeLab];
        self.timeLab = timeLab;
        
    }
    return self;
}
-(void)setNewsF:(CommonNewsFrame *)newsF{
    _newsF = newsF;
    [self settingData];
    [self settingFrame];
}
-(void)settingData{
    BSNewsModel *news;
    
    if (_type == NewsTypeRemind) {
        news =(RemindModel *)_newsF.news;
    }else if(_type == NewsTypeRecommend){
        news = (RecommendModel *)_newsF.news;
    }else{
        news = (CommonNews *)_newsF.news;
    }
    
    self.titleLab.text = news.title;
    
    NSDate *date = [NSDate date:news.date WithFormat:YMDHMS];
    
    NSString *fb_date = [date stringWithFormat:YMD];
    
    NSString *today = [NSDate stringOfToday];
    NSString *yesterday = [NSDate stringOfYesterday];
    
    self.timeLab.textColor = [UIColor darkTextColor];
    self.timeLab.font = kFont(13);
    NSString *showTime = fb_date;
    
    if ([fb_date isEqualToString:today]) {
        showTime = @"今天";
        self.timeLab.textColor = [UIColor redColor];
        self.timeLab.font = BFont(14);
    }
    if ([fb_date isEqualToString:yesterday]) {
        showTime = @"昨天";
        self.timeLab.textColor = [UIColor redColor];
        self.timeLab.font = BFont(14);
    }
    self.timeLab.text = showTime;
}
-(void)settingFrame{
    self.titleLab.frame = _newsF.titleF;
    self.timeLab.frame = _newsF.dateF;
    //    self.line.frame = CGRectMake(0, self.timeLab.maxY+5, kScreenW, 1);
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *cellId = @"cellId";
    CommonNewsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[CommonNewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

@end
